import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

import Recommend from "../views/home/recommend.vue";
import Hotsong from "../views/home/hotsong.vue";
import Search from "../views/home/search.vue";

const routerPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
	return routerPush.call(this, location).catch(error => error)
}


Vue.use(VueRouter)

// 路由懒加载(vue性能优化手段之一)
const routes = [{
		path: '/',
		name: 'Home',
		component: Home,
		// 嵌套路由
		children: [{
				path: '',
				component: Recommend
			},
			{
				path: 'hotsong',
				component: Hotsong
			},
			{
				path: 'search',
				component: Search
			}
		]
	},
	{
		path: '/playlist',
		name: 'Playlist',
		component: () => import( /* webpackChunkName: "about" */ '../views/playlist')
	},
	{
		path: '/about',
		name: 'About',
		// route level code-splitting
		// this generates a separate chunk (about.[hash].js) for this route
		// which is lazy-loaded when the route is visited.
		component: () => import( /* webpackChunkName: "about" */ '../views/About.vue')
	},
	{
		path: '/login',
		component: () => import( /* webpackChunkName: "login" */ '../views/login.vue')
	},
	{
		path: "/song",
		component: () => import( /* webpackChunkName: "song" */ '../views/song.vue')
	}
]

const router = new VueRouter({
	routes
})

export default router
